package util;
import java.util.ArrayList;
import java.util.Iterator;

import oscP5.OscIn;

public class OscFsr implements OscListener{
	private int noiseThreshold;
	private int id;
	public int val;
	private ArrayList listeners;
	
	public OscFsr(OscHub osc, int id, int noise) {
		this.val = 0;
		this.id = id;
		this.noiseThreshold = noise;
		osc.addListener(this);
	}
	
	public void addListener(OscFsrListener fsrl){
		listeners.add(fsrl);
	}

	public int getId() {
		return id;
	}
	
	public int getVal() {
		return val;
	}

	public void setId(int id) {
		this.id = id;
	}
	

	public int getNoiseThreshold() {
		return noiseThreshold;
	}

	public void setNoiseThreshold(int noiseThreshold) {
		this.noiseThreshold = noiseThreshold;
	}

	public void oscEvent(OscIn oscIn) {
		if(oscIn.checkAddrPattern("CUI")) return;
		if(oscIn.getInt(0) != id) return;
		val = oscIn.getInt(1);
		notifyChanged();
	}
	
	public void notifyChanged(){
		Iterator i = listeners.iterator();
		while(i.hasNext())
			((OscFsrListener)i.next()).fsrChanged(this);
	}

}
